package com.tt.aile.search.controller;

import com.tt.aile.common.pojo.PageResult;
import com.tt.aile.search.pojo.Goods;
import com.tt.aile.search.pojo.SearchRequset;
import com.tt.aile.search.pojo.SearchResult;
import com.tt.aile.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;

/**
 * @author 86176 shkstrat
 * @date 2020/11/21 - 17:53
 */
@Controller
public class SearchController {

    @Autowired
    SearchService searchService;

    @PostMapping("/page")
    public ResponseEntity<SearchResult> queryGoods(@RequestBody SearchRequset searchRequset){
        //System.out.println("SearchController--------sssssss-");
        SearchResult result = this.searchService.queryGoods(searchRequset);
        if (result==null || CollectionUtils.isEmpty(result.getItems())){
            return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
        }
        return ResponseEntity.ok(result);
    }
}
